/**
 * $Id: EntitySupport.java 23 2011-06-15 13:58:35Z feigme $
 */
package com.iary.domain.model;

@SuppressWarnings("unchecked")
public abstract class EntitySupport<T extends EntitySupport> implements
		Entity<T, Long> {

	protected Long id;

	@Override
	public final Long getId() {
		return id;
	}

	@Override
	public final boolean sameIdentityAs(T other) {
		return other != null && this.id != null && this.id.equals(other.id);
	}

	@Override
	public final int hashCode() {
		return id == null ? 0 : id.hashCode();
	}

	@Override
	public final boolean equals(final Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		return sameIdentityAs((T) o);
	}

}
